<!-- BEGIN LOGIN -->
<div id="login">
    <!-- BEGIN LOGIN FORM -->
    <form id="loginform" class="form-vertical no-padding no-margin">


        <!-- FB Login -->
        <a href="javascript:fb_login()" class="btn btn-block btn-primary login-button"><b class="icon-signin icon-white"></b> FB Login</a>
        <a href="<?php echo base_url() ?>" class="btn btn-block btn-danger login-button"><b class="icon-home icon-white"></b> Back to Homepage</a>
    </form>
    <!-- END LOGIN FORM -->
</div>
<!-- END LOGIN -->




<script>
    function fb_login()
    {
        FB.login(function(response) {


            if (response.authResponse) {
                var accessToken = FB.getAuthResponse()['accessToken'];
                console.log('Access Token = ' + accessToken);
                window.location.href = '<?php echo base_url() ?>login?accessToken=' + accessToken;
            } else {
                console.log('User cancelled login or did not fully authorize.');
            }


        }, {scope: '<?php echo $this->config->item('fb_scope') ?>'});
    }
</script>

<div id="fb-root"></div>
<script>
    var FB = null;
    /*Additional JS functions here*/
    window.fbAsyncInit = function() {
        FB.init({
            appId: '<?php echo $this->config->item('fb_app_id') ?>',
            status: true,
            cookie: true,
            xfbml: true
        });
    };
    /*Load the SDK asynchronously*/
    (function(d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {
            return;
        }
        js = d.createElement('script');
        js.id = id;
        js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>
